<?php

require_once("spdo.php");

function foo()
{
	/*
	 *  get single global instance
	 */
	 
	$pdo = SPDO::getInstance();
	
	
	
	/*
	 * sample query
	 */
	
	echo "<pre>";
	$stmt = $pdo->query("SELECT * FROM `users`");
	
	foreach($stmt as $row)
	{
		print_r($row);
	}
	echo "</pre>";
	
	
	
	
	
	/*
	 * modifyTable
	 */	 
	
	
	// fill values to assoc. array	
	$set = array();
	$set["field1"] = "value1";
	$set["field2"] = 5;
	$set["field3"] = NULL;
	
	
	// insert new line
	$pdo->modifyTable("test", $set);
	// SQL: INSERT INTO `test` (field1, field2, field3) VALUES ('value1', '5', NULL)
	
	// update
	$pdo->modifyTable("test", $set, "id = '5'");
	// SQL: UPDATE `test` SET field1 = 'value1', field2 = '5', field3 = NULL WHERE id = '5'
	
}

try
{
	$pdo = SPDO::connect("mysql:dbname=test;host=localhost", "root", "root");
	$pdo->exec("SET NAMES 'utf8'");

	foo();
}
catch(Exception $e)
{
	echo $e->getMessage();
}



?>
